def gcd(a,b):
        """ the euclidean algorithm """
        while a:
                a, b = b%a, a
        return b

def checklen(w):
	i = 0
	while True:
		if w[i] == 1 and i != 2:
			break
		i += 1
	return i

def expand(w, m, n):
	s = gcd(m,n)

	i = 0
	while i < len(w):
		# check the cancel case
		
		if i + n * s < len(w):
			exp = w[i] / 2
			is_cancel = True
			for j in range(m/s):
				if w[i + j * s] != 2 * exp:
					is_cancel = False
			for j in range(n/s - m/s):
				if w[i + m + j * s] != exp:
					is_cancel = False
			if is_cancel:
				for j in range(n/s):
					w[i + j * s] = 0
		
		exp = w[i] / 2
		w[i] = w[i] % 2
		if exp > 0:
			w[i+m] += exp
			w[i+n] += exp
		i += 1
	
	last_one = len(w)
	for i in range(len(w)):
		if w[len(w) - i - 1] == 0:
			last_one -= 1
		else:
			break
	
	return w[:last_one]

w = [0] * 10000
w[0] = 4

ans = expand(w, 2, 5)
print ans#, checklen(ans)
